//
//  CourseUseageModel.m
//  ShowYork
//
//  Created by hxh on 2020/9/14.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "LessonUseageModel.h"

@implementation LessonUseageModel
MJCodingImplementation

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.continuousTime = @0;
        self.allTime = @0;
        self.todayTime = @0;
        self.lastUpdate = @0;
        self.createTime = @0;
        self.currentTodayTime = @0;
    }
    return self;
}

+ (BOOL)supportsSecureCoding{
    return YES;
}

- (void)save{
    NSData * data = nil;
    if (@available(iOS 11.0, *)) {
        data = [NSKeyedArchiver archivedDataWithRootObject:self requiringSecureCoding:YES error:nil];
    } else {
        data = [NSKeyedArchiver archivedDataWithRootObject:self];
    }
    NSString *key = [NSString stringWithFormat:@"%@/Useage",[RPAppManager getCustomerId]];
    [[NSUserDefaults standardUserDefaults]setObject:data forKey:key];
    [[NSUserDefaults standardUserDefaults]synchronize];
}

+ (LessonUseageModel *)getUseage{
    NSString *key = [NSString stringWithFormat:@"%@/Useage",[RPAppManager getCustomerId]];
    NSData *data = [[NSUserDefaults standardUserDefaults]objectForKey:key];
    NSError *error = nil;
    if (@available(iOS 11.0, *)) {
        LessonUseageModel *model = [NSKeyedUnarchiver unarchivedObjectOfClass:[self class] fromData:data error:&error];
        if (model == nil) {
            model = [[LessonUseageModel alloc]init];
        }
        return model;
    } else {
        LessonUseageModel *model = [NSKeyedUnarchiver unarchiveObjectWithData:data];
        return model;
    }
}
+ (void)deleteUseage{
    NSString *key = [NSString stringWithFormat:@"%@/Useage",[RPAppManager getCustomerId]];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:key];
    [[NSUserDefaults standardUserDefaults]synchronize];
}
@end
